<%-- 
    Document   : myRounds
    Created on : 26/03/2012, 04:51:44 PM
    Author     : John
--%>

<%@page import="riteservices.model.bean.Rating"%>
<%@page import="com.sun.imageio.spi.RAFImageInputStreamSpi"%>
<%@page import="riteservices.model.bean.User"%>
<%@page import="riteservices.model.bean.Route"%>
<%@page import="java.util.List"%>
<%@page import="riteservices.model.bean.Round"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>YoTeLlevo.Com :: Mis Rutas</title>
        
        <link rel="stylesheet" type="text/css" href="public/bootstrap/css/bootstrap-responsive.css" />
         <link rel="stylesheet" type="text/css" href="public/bootstrap/css/bootstrap.css" />
         <link rel="stylesheet" type="text/css" href="public/css/appStyle.css" />
         <link rel="stylesheet" type="text/css" href="public/css/south-street/jquery-ui.css" />
          <link rel="stylesheet" type="text/css" href="public/css/anytimec.css" />
          
         <script type="text/javascript" src="public/js/jquery.min.js"></script>
         <script type="text/javascript" src="public/js/jquery_ui.js"></script>
         <script type="text/javascript" src="public/js/appJS.js"></script>
         <script type="text/javascript" src="public/js/anytimec.js"></script>
         <script type="text/javascript" src="public/js/anytimetz.js"></script>
         <script type="text/javascript">
             function calificar(idRound ,rate){
                 $.post("RateUser", {id:idRound, rate: rate}, function(){
                     window.location.href = "ListOwnerRounds";
                 });
             }
             
             function actualizar(idRating, rate){
                 $.post("UpdateRate", {id:idRating, rate: rate},function(){
                     window.location.href = "ListOwnerRounds";
                 });
             }
         </script>
    </head>
    <body>
        
        <div class="navbar navbar-top">
                <div class="navbar-inner">
                 <div class="container">
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                   
                    </a>
                    <a class="brand" href="home.jsp">YoTeLlevo.Com</a>
                    <div class="nav-collapse">
                        <ul class="nav">
                            <li><a href="Home">Inicio</a></li>
                            <li><a href="LogOut">Salir</a></li>
                        </ul>
                    </div><!--/.nav-collapse -->
                 </div>
                </div>
            </div>
        <div class="container-fluid">
            
            <%
            List<Round> myRounds = (List<Round>)request.getSession().getAttribute("userRoundsList");
            List<Round> rounds2 = (List<Round>)request.getSession().getAttribute("userRoundsListHit");     
          ;  User user = (User) request.getSession().getAttribute("user");               
           %>
            
           
           <h1>Mis Rutas</h1>
           <br>

            <div id="ownerRoundsList" class="well span7 userRoundsList">
                <h3>Rondas que he creado.</h3>
            <button style="float: right;margin-top: -25px;" id="createRoundButton" class="btn btn-success dropdown-toggle" data-toggle="dropdown"><h3>Dar de alta una ronda</h3></span></button>

                <%
                       
                %>
                 <br>
                <br>
                <% 
                    for(int i= 0; i<myRounds.size(); i++)
                    {
                        out.print("<div class='mapItem'><a>"+myRounds.get(i).getRoute().getOrigin()+" = = > "+myRounds.get(i).getRoute().getDestiny()+"</a><!--<div><img src='public/images/map_icon.gif' width='50px;' /></div>-->"
                                + "<br/><a class='deleteRoundLink' href='DeleteRound?id="+myRounds.get(i).getIdRound()+"'>Eliminar</a><a class='editRoundLink' href='EditRound?id="+myRounds.get(i) .getIdRound()+"&tipo=0'>Editar</a><hr></div>");
                    }
                %>
                
            </div>
            <div id="passengerRoundsList" class="well span7 userRoundsList">
                <h3>Rutas en las que soy pasajero</h3>
                <br>
                 <% 
                    for(int i= 0; i<rounds2.size(); i++)
                    {
                        out.print("<div class='mapItem'>"
                                +"Destino: <a href='EditRound?id="+rounds2.get(i) .getIdRound()+"&tipo=1'>"+ rounds2.get(i).getRoute().getDestiny() +"</a><br/>");
                        Rating rating = null;
                        for(Rating r: rounds2.get(i).getRatings()){
                            if(r.getUserByHitchker().getIdUser()==user.getIdUser()){
                                rating = r;
                            }
                        }
                        out.print("Calificación para el dueño del a ronda: ");
                        for(int j = 0; j<5 ; j++)
                               {%>
                               <input type='radio' class='ratingRadio' value='<% out.print(j+1); %>' name="radioRating-<% out.print(rounds2.get(i).getIdRound()); %>" id='radioRating-<% out.print(rounds2.get(i).getIdRound()); %>'  <% if(rating!=null){ 
                                   out.print("onclick='javascript:actualizar("+rating.getIdRating()+","+(j+1)+");' ");
                                   if(rating.getRating()==j+1){
                                       out.print("checked");
                                   }
                               }else{
                                  out.print("onclick='javascript:calificar("+rounds2.get(i).getIdRound()+","+(j+1)+");'"); 
                               } 
                               %>  /> <% out.print(j+1);
                               }
                        
                        out.println("<hr></div>");
                    }
                %>
            </div>
        </div>
    </body>
</html>
